import React from 'react';
import {Link} from "react-router-dom";
import GUtils from "@/utils";
import classNames from "classnames";

const Config = (Action) => {
    const Handlers = {
        enabled({id,enabled,name}) {
            enabled=!enabled;
            let op = enabled ? "启用" :"禁用";
            GUtils.confirm(op,`确认${op}门店 [${name}] 吗?`,()=>{
                Action.enabled(id, enabled);
            });
        }
    }
    const columns = [

        {title:"工位名称",dataIndex:"name",width:100,render: (v,vo)=><Link to={`detail/view?id=${vo.id}`}>{v}</Link>},
        {title:"门店名称",dataIndex:"shopName",width:120},
        {title:"状态",dataIndex:"enabled",width:60, render:GUtils.renderEnabledValue},
        {title:"工位状态",dataIndex:"status",width:60, render: v => GUtils.renderShopStationStatus(v)},
        {title:"关联设备",dataIndex:"deviceSimpleList",width:120, render(list){
                let {PAGE_DEVICE, PAGE_DETAIL}=window.CONFIG;
                return list.map(o=> <div key={o.id}>  <Link  to={`${PAGE_DEVICE}${PAGE_DETAIL}?id=${o.id}`} className={classNames(o.enabled||"danger")}>{o.name} {o.enabled || GUtils.renderEnabledValue(o.enabled)}</Link></div>)
        }},


        {title: '操作',dataIndex: 'id',width: 150,render(id,vo){
            let {enabled} = vo;
                return <div>
                    <Link to={`detail/view?id=${id}`} className="mr-8">查看详情</Link>
                    <Link to={`detail/edit?id=${id}`} className="mr-8">编辑</Link>

                    <Link onClick={Handlers.enabled.bind(this,vo)}>{enabled ? "禁用" :"启用"}</Link>
                </div>
            }},
    ];
    return {
        ...window.CONFIG.getPagerConfig(Action), columns
    };
};


export default Config;
